package com.talkweb.osmharmony.views.overlay;


import com.talkweb.osmharmony.events.MapEventsReceiver;
import com.talkweb.osmharmony.util.GeoPoint;
import com.talkweb.osmharmony.views.MapView;
import com.talkweb.osmharmony.views.Projection;
import ohos.app.Context;
import ohos.multimodalinput.event.MmiPoint;
import ohos.multimodalinput.event.TouchEvent;

/**
 * Empty overlay than can be used to detect events on the map,
 * and to throw them to a MapEventsReceiver.
 *
 * @author M.Kergall
 * @see MapEventsReceiver
 */
public class MapEventsOverlay extends Overlay {

    private MapEventsReceiver mReceiver;

    /**
     * Use {@link #MapEventsOverlay(MapEventsReceiver)} instead
     */
    @Deprecated
    public MapEventsOverlay(Context ctx, MapEventsReceiver receiver) {
        this(receiver);
    }

    /**
     * @param receiver the object that will receive/handle the events.
     *                 It must implement MapEventsReceiver interface.
     */
    public MapEventsOverlay(MapEventsReceiver receiver) {
        super();
        mReceiver = receiver;
    }

    @Override
    public boolean onSingleTapConfirmed(TouchEvent e, MapView mapView) {
        MmiPoint mmiPoint = e.getPointerPosition(0);
        Projection proj = mapView.getProjection();
        GeoPoint p = (GeoPoint) proj.fromPixels((int) mmiPoint.getX(), (int) mmiPoint.getY());
        return mReceiver.singleTapConfirmedHelper(p);
    }

    @Override
    public boolean onLongPress(TouchEvent e, MapView mapView) {
        MmiPoint mmiPoint = e.getPointerPosition(0);
        Projection proj = mapView.getProjection();
        GeoPoint p = (GeoPoint) proj.fromPixels((int) mmiPoint.getX(), (int) mmiPoint.getY());
        //throw event to the receiver:
        return mReceiver.longPressHelper(p);
    }

}

